package com.zzyl.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    /**
     * 获取所有护理等级信息
     * @return
     */
    @Override
    public List<NursingLevelVo> all() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelMapper.all();
        return nursingLevelVos;
    }

    /**
     *添加护理等级信息
     * @param nursingLevelDto
     */
    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevel.setLplanId(nursingLevelDto.getPlanId());
        nursingLevelMapper.add(nursingLevel);

    }

    /**
     * 分页查询护理等级信息
     * @param pageNum
     * @param pageSize
     * @param name
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingLevelVo> getByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevelVo> page = nursingLevelMapper.getByPage(name,status);
        PageResponse<NursingLevelVo> nursingLevelVoPageResponse = new PageResponse<>(page);
//        nursingLevelVoPageResponse.setPage(page.getPageNum());
//        nursingLevelVoPageResponse.setPages((long) page.getPages());
//        nursingLevelVoPageResponse.setPageSize(page.getPageSize());
//        nursingLevelVoPageResponse.setTotal(page.getTotal());
        nursingLevelVoPageResponse.setRecords(page.getResult());
        return nursingLevelVoPageResponse;
    }

    /**
     * 根据id查询护理等级信息
     * @param id
     * @return
     */
    @Override
    public NursingLevelVo getById(Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelMapper.getById(id);

        return nursingLevelVo;
    }

    /**
     * 编辑更新护理等级信息
     * @param nursingLevelDto
     */
    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();
        BeanUtils.copyProperties(nursingLevelDto,nursingLevel);
        nursingLevel.setLplanId(nursingLevelDto.getPlanId());

        nursingLevelMapper.update(nursingLevel);
    }

    /**
     * 根据id删除护理等级信息
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    /**
     * 启用/禁用护理等级信息
     * @param id
     * @param status
     */
    @Override
    public void enableDisable(Long id, Integer status) {
        NursingLevel nursingLevel = new NursingLevel();
        NursingLevelVo nursingLevelVo = nursingLevelMapper.getById(id);
        BeanUtils.copyProperties(nursingLevelVo,nursingLevel);
        nursingLevel.setId(id);
        nursingLevel.setStatus(status);
        nursingLevelMapper.update(nursingLevel);
    }
}
